﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for HNCData
/// </summary>
public class HNCData
{
    HNCDataContext hncdata = new HNCDataContext();
    public HNCData()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static List<Product> GetAllProductByCateID(int CateID)
    {
        try
        {
            HNCDataContext data = new HNCDataContext();
            var query = (from a in data.Products
                         where a.CateID == CateID
                         orderby Convert.ToInt32(a.Order) ascending, a.Editdate descending
                         select a);
            return query.ToList<Product>();
        }
        catch (Exception)
        {
            return null;
        }
    }

    public static List<Category> GetAllCategoryByParentID(int CateID)
    {
        try
        {
            HNCDataContext data = new HNCDataContext();
            var query = (from a in data.Categories
                         where a.ParentID == CateID
                         orderby Convert.ToInt32(a.Order) ascending
                         select a);
            return query.ToList<Category>();
        }
        catch (Exception)
        {
            return null;
        }
    }

    public static Product GetOne(int ProductID)
    {
        try
        {
            HNCDataContext data = new HNCDataContext();
            var query = (from a in data.Products
                         where a.ProductID == ProductID
                         select a).SingleOrDefault();
            return query;
        }
        catch (Exception)
        {
            return null;
        }
    }
}